﻿using System;
using System.Xml.Serialization;

namespace GeneralTool.CoreLibrary.Licenses
{
    /// <summary>
    /// 密钥信息
    /// </summary>
    public struct LicenseInfo
    {
        /// <summary>
        /// 硬件唯一id
        /// </summary>
        public string DeviceHardId { get; set; }
        /// <summary>
        /// 密钥创建时间
        /// </summary>

        public DateTime CreateTime { get; set; }
        /// <summary>
        /// 密钥过期时间
        /// </summary>
        public DateTime ExpireTime { get; set; }
        /// <summary>
        /// 密钥上次使用时间
        /// </summary>
        public DateTime? PrevUseTime { get; set; }
        /// <summary>
        /// 获取密钥剩余时间
        /// </summary>
        [XmlIgnore]
        public TimeSpan FreeTime
        {
            get
            {
                var freeTime = this.PrevUseTime == null ? this.ExpireTime - this.CreateTime : this.ExpireTime - this.PrevUseTime.Value;
                var freeTime2 = this.ExpireTime - DateTime.Now;
                if (freeTime2 < TimeSpan.Zero)
                    freeTime = freeTime2;
                return freeTime;
            }
        }

    }
}
